<template>
  <div id="unit" class="flex" >
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:cri>
        <div novalidate class="form-inline" partial>

          <!-- <div class="form-group form-input-group">
            <label for="f_slice_area" class = "control-form">片区:</label>
            <v-select :value.sync="model.f_slice_area" :options='sliceArea' placeholder='片区/管理站' close-on-select
              v-model='model.f_slice_area' v-ref:slice></v-select>
          </div> -->
          <div class="form-group form-input-group">
            <label for="f_adjustable_name" class = "control-form">调压箱名称:</label>
            <v-select :value.sync="model.f_adjustable_name" condition="b.id= '{}' " :options='$parent.$parent.boxname' placeholder='调压箱' close-on-select
              v-model='model.f_adjustable_name' :search = "true" v-ref:adjustable></v-select>
          </div>
          <div class="form-group">
            <button class="btn btn-success width-80" @click="search()" v-el:cx>查询</button>
            <export-excel :data="{condition: $parent.model.condition}"
            sqlurl="rs/logic/exportfile" :bean="'调压箱汇总查询导出'"></export-excel>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th>序号</th>
            <th>片区/管理站</th>
            <th>调压箱名称</th>
            <th>小区名称</th>
            <th>用户数量</th>
          </tr>
        </template>
        <template partial='body' >
          <td style="text-align: center;" :class = "{'bg-info' : row.f_slice_area === '小计', 'bg-success' : row.f_slice_area === '合计', 'bg-danger' : row.f_slice_area === '总计' }">{{$index+1}}</td>
          <td v-if="model.rows[$index-1] && model.rows[$index-1].f_slice_area === row.f_slice_area"></td>
          <td v-else :class = "{'bg-info' : row.f_slice_area === '小计', 'bg-success' : row.f_slice_area === '合计', 'bg-danger' : row.f_slice_area === '总计' }">{{row.f_slice_area}}</td>
          <td :class = "{'bg-info' : row.f_slice_area === '小计', 'bg-success' : row.f_slice_area === '合计', 'bg-danger' : row.f_slice_area === '总计' }">{{row.f_adjustable_name}}</td>
          <td :class = "{'bg-info' : row.f_slice_area === '小计', 'bg-success' : row.f_slice_area === '合计', 'bg-danger' : row.f_slice_area === '总计' }">{{row.f_residential_area}}</td>
          <td :class = "{'bg-info' : row.f_slice_area === '小计','bg-success' : row.f_slice_area === '合计', 'bg-danger' : row.f_slice_area === '总计' }">{{row.users}}</td>
        </template>
      </data-grid>
  </criteria-paged>
 </div>
</template>
<script>
import { PagedList } from 'vue-client'
import AppData from '../../../../stores/AppData'
import co from 'co'
import * as Util from '../../../Util'

// let getSliceGen = function * (self, val) {
//   let slices = yield self.$post('/rs/search', {source: 'tool.getFullTree(this.getParent().getAllChildrens().where(row.getType() == $区$))', userid: '0'}, {resolveMsg: null, rejectMsg: null})
//   self.sliceArea = []
//   slices.data.forEach((item, next) => {
//     let temp = {}
//     temp.label = item.name
//     temp.value = item.name
//     self.sliceArea.push(temp)
//   })
// }
export default {
  title: '调压箱汇总信息',
  data () {
    return {
      sliceArea: [],
      model: new PagedList('rs/sql/boxSummarize', 150)
    }
  },
  props: [],
  ready () {
    this.model.search('1=1')
  },
  methods: {
    // getSlice () {
    //   let SliceGen = getSliceGen(this)
    //   co(SliceGen)
    // },
    search () {
      this.model.search()
    }
    // getPargram () {
    //   let condition = `id >= \'${this.$refs.paged.$refs.cri.model.f_adjustable_name}\'`
    //   return {condition: condition}
    // }
  },
  watch: {
    'model.rows' (val) {
      val.forEach((item, index) => {
        if (item.f_adjustable_name === '合计' && item.users === 0) {
          val.splice(index, 1)
        }
      })
    }
  },
  computed: {
    boxname () {
      let arr = []
      AppData.getAdjustable().forEach((item) => {
        let temp = {}
        temp.label = `[${item.value.f_adjustable_id}]-${item.label}`
        temp.value = `${item.value.id}`
        arr.push(temp)
      })
      console.log(AppData.getAdjustable())
      return [{label: '全部', value: ''}, ...arr]
    },
    filiales () {
      return [{label: '全部', value: ''}, ...AppData.getParam('分公司')]
    }
  }
}
</script>
